﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace PeisongWeb
{
    public partial class seller_reportBusinessList : customerPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptBind();
            }
        }

        private void rptBind()
        {
            int companyid = logic.customer.getCompanyId();
            string searstr = txt_rbno.Value.Trim();

            StringBuilder where = new StringBuilder();
            where.AppendFormat(" rbno in (select rbno from vw_order a where a.sellerid={0})", companyid);
            if (!string.IsNullOrEmpty(searstr))
                where.AppendFormat(" and rbno='{0}'", Library.StringLbl.FormatSearchKey(searstr));

            DataSet ds = DAL.reportBusiness.list(where.ToString(), "createdt desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void btn_select_Click(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void rpt_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal lblOrderAmount = e.Item.FindControl("lblOrderAmount") as Literal;
               // Literal lblProductNum = e.Item.FindControl("lblProductNum") as Literal;
               // Literal lblOrderNum = e.Item.FindControl("lblOrderNum") as Literal;

                DataRowView dv = e.Item.DataItem as DataRowView;

                DataRow dr = DAL.DbHelper.ExecuteDataRow("p_reportBusiness_price_fixed", dv["rbno"].ToString(), logic.customer.getCompanyId());
                lblOrderAmount.Text = string.Format("{0:F2}", dr["amountSum"]);
               // lblOrderNum.Text = string.Format("{0}", dr["orderCount"]);
                //lblProductNum.Text = string.Format("{0}", dr["productCount"]);
            }
        }
    }
}
